/**
 * 
 */
package ihm.actions.character_creator;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

import systems.languages.MultiLanguages;

/**
 * @author Baptiste Legrand & Benjamin Orman
 * @version 1.0
 */
public class CharacterNameAction
    implements FocusListener {

  private JTextField source;
  private String name;
  
  public CharacterNameAction(JTextField source)
  {
    this.source = source;
  }
  
  private void updateName()
  {
    this.name = this.source.getText();
    this.name = this.name.trim();
    //this.source.setText(this.name);
    if(this.name.isEmpty())
    {
      System.out.println("Chaine vide");
      this.source.setText(MultiLanguages.getProperties("model.defaultCharacter.name"));
    }
  }

  @Override
  public void focusGained(FocusEvent e) {    
  }

  @Override
  public void focusLost(FocusEvent e) {
    System.out.println("Action ");
    updateName();
  }

}
